package vapor.aquila.client.game;

/**
 * A World consists of a collection of tiles, which represent the world, all the
 * units in the world, all the cities in the world and basically everything but
 * the players.
 * 
 * @author Travis Gockel
 */
public class World
{	
	//	why isn't this a more advanced data type?
	//	Google App Engine and DataNucleus work best with POJOs -- although
	//	it might be best to put this in an R-Tree or something
	private Tile[][] m_map;
	private int m_mapSizeLat, m_mapSizeLon;
	
	//	CONSTRUCTORS	//////////////////////////////////////////////////////////
	public World(int sizeLat, int sizeLon)
	{
		m_mapSizeLat = sizeLat;
		m_mapSizeLon = sizeLon;
		m_map = new Tile[m_mapSizeLat][m_mapSizeLon];
	}
	
	//	ACCESSORS	//////////////////////////////////////////////////////////////
	/**
	 * The latitude is the distance the map is in east-west.
	 */
	public int getMapSizeLatitude()
	{
		return m_mapSizeLat;
	}
	
	/**
	 * The longitude is the distance the map is in north-south.
	 */
	public int getMapSizeLongitude()
	{
		return m_mapSizeLon;
	}
	
	/**
	 * Gets a 
	 * @param lat
	 * @param lon
	 * @return The map tile in most cases; null if the map has not been generated
	 * @throws ArrayIndexOutOfBoundsException If lat/lon are outside of the map.
	 */
	public Tile getMapTile(int lat, int lon)
	{
		return m_map[lat][lon];
	}
	
	//	FUNCTIONS	////////////////////////////////////////////////////////////
	public void generate(IWorldGenerator generator)
	{
		Tile[][] tiles = generator.generate(m_mapSizeLat, m_mapSizeLon);
		
		for (int x = 0; x < m_mapSizeLat; x++)
			for (int y = 0; y < m_mapSizeLon; y++)
				m_map[x][y] = tiles[x][y];
	}
}
